numpy topk

47

>>> a = np.array([9, 4, 4, 3, 3, 9, 0, 4, 6, 0])
array([9, 4, 4, 3, 3, 9, 0, 4, 6, 0])

>>> ind = np.argpartition(a, -4)[-4:]
array([1, 5, 8, 0])

>>> top4 = a[ind]
array([4, 9, 6, 9])

Comments

Submit
0 Comments